﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YogaStudio.Data.Domain;

namespace YogaStudio.WebUI.Models
{
    public class SectionViewModel
    {
        protected Section _source;
        public int Id { get; set; }
        public virtual Course Course { get; set; }
        public string CourseName { get; set; }
        public virtual Faculty Faculty { get; set; }
        public string FacultyName { get; set; }
        public virtual Schedule Schedule { get; set; }
        public virtual Semester Semester { get; set; }
        public string SemesterName { get; set; }
        public int? Year { get; set; }
        public DateTime? FromDate { get; set; }
        public DateTime? ToDate { get; set; }
        public virtual Room Room { get; set; }
        public double Price { get; set; }
        public int Capacity { get; set; }
        public int Volume { get; set; }
        public virtual ICollection<Customer> Customers { get; set; }

        public static implicit operator SectionViewModel(Section section)
        {
            return new SectionViewModel
            {
                _source = section,
                Id = section.Id,
                Course = section.Course,
                CourseName = (section.Course != null) ? section.Course.CourseName : null,
                Faculty = section.Faculty,
                FacultyName = (section.Faculty != null) ? section.Faculty.FullName : null,
                Schedule = section.Schedule,
                Semester = (section.Schedule != null) ? section.Schedule.Semester : null,
                SemesterName = (section.Schedule != null && section.Schedule.Semester != null) ? section.Schedule.Semester.SemesterName : null,
                Year = (section.Schedule != null) ? section.Schedule.Year : (int?)null,
                FromDate = (section.Schedule != null) ? section.Schedule.FromDate : (DateTime?)null,
                ToDate = (section.Schedule != null) ? section.Schedule.ToDate : (DateTime?)null,
                Customers = section.Customers,
                Room = section.Room,
                Price = section.Price,
                Capacity = section.Capacity,
                Volume = (section.Customers != null) ? section.Customers.Count : 0,
            };
        }
    }
}